Skip to content

chore: unify resilience tests and add 401/mid-execution-maintenance scenarios#6807

Merged
PeterSchafer merged 1 commit into
mainfrom
chore/CLI-1494_fault_injection
May 19, 2026
Merged

chore: unify resilience tests and add 401/mid-execution-maintenance scenarios#6807
PeterSchafer merged 1 commit into
mainfrom
chore/CLI-1494_fault_injection

Conversation

@PeterSchafer

Copy link
Copy Markdown
Contributor

Pull Request Submission Checklist

  • Follows CONTRIBUTING guidelines
  • Commit messages
    are release-note ready, emphasizing
    what was changed, not how.
  • Includes detailed description of changes
  • Contains risk assessment (Low | Medium | High)
  • Highlights breaking API changes (if applicable)
  • Links to automated tests covering new functionality
  • Includes manual testing instructions (if necessary)
  • Updates relevant GitBook documentation (PR link: ___)
  • Includes product update to be announced in the next stable release notes

What does this PR do?

This PR moves existing separate tests into a single test suite for easier overview and maintenance.

Where should the reviewer start?

How should this be manually tested?

What's the product update that needs to be communicated to CLI users?

N/A

Risk assessment (Low | Medium | High)?

Low, changes tests only

@PeterSchafer PeterSchafer requested review from a team as code owners May 14, 2026 16:39
@snyk-io

snyk-io Bot commented May 14, 2026

Copy link
Copy Markdown

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@snyk-pr-review-bot

This comment has been minimized.

Comment thread test/acceptance/fake-server.ts Outdated
Comment thread test/jest/acceptance/resilience.spec.ts
Comment on lines -63 to -79
it('does not attempt any retries', async () => {
await runSnykCLI(`test -d --log-level=trace`, {
env: {
...env,
// apply a user configured attempts of 10
INTERNAL_NETWORK_REQUEST_MAX_ATTEMPTS: '10',
},
});

// Count how many times an endpoint was hit
const requests = server.getRequests();
const actualNetworkAttempts = requests.filter(
(r) => r.url.includes('/test-dep-graph') || r.url.includes('/vuln/'),
).length;

expect(actualNetworkAttempts).toBe(1);
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm I think this test is missing in the new file?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not fully sure why: the PR description mentions "remove individual test" but the backing ticket does not mention any of that

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please clarify what you mean? What is the problem you think needs to be addressed?

Comment on lines -31 to -32
INTERNAL_NETWORK_REQUEST_MAX_ATTEMPTS: '1',
INTERNAL_NETWORK_REQUEST_RETRY_AFTER_SECONDS: '1',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also these two are not present in the new file

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this was intentional!

INTERNAL_NETWORK_REQUEST_RETRY_AFTER_SECONDS has no real meaning in the test
and INTERNAL_NETWORK_REQUEST_MAX_ATTEMPTS is replaced by the official env var SNYK_MAX_ATTEMPTS

envOverrides: {
SNYK_TIMEOUT_SECS: String(TIMEOUT_SECS),
},
skip: ['container sbom scratch'],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm do we want to skip this here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We currently skip these tests for all cases that do not yet behave consistent. This decouples solving of the inconsistency from merging the test suite.

Comment on lines -95 to -100
// Should send instrumentation data even on timeout
const requests = server.getRequests();
const instrumentationRequest = requests.find((r) =>
r.url?.includes(`/api/hidden/orgs/${orgId}/analytics`),
);
expect(instrumentationRequest).toBeDefined();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is also absent in the new file

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

Comment on lines -44 to -48
beforeEach(async () => {
initialConfig = await getCliConfig();
// Set server to delay responses longer than the timeout (10s > 5s timeout)
server.setResponseDelay(SERVER_DELAY_MS);
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have beforeEach in the new file, is that intentional?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now in the setup function for the scenario.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'monitor',
'whoami',
'auth 11111111-2222-3333-4444-555555555555',
'sbom --org=11111111-1111-1111-1111-111111111111 --format=cyclonedx1.4+json',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before it was:

sbom --org=test-org --format=cyclonedx1.4+json

Any reason for changing the org here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is just about aligning the test with baseEnv defined in lines 195-201

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

org-id vs org-slugname, internally we use only org-id, if a slugname is specified a lookup needs to happen, which I wanted to avoid in the test.

@danskmt danskmt May 19, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have any test that tests this lookup happens / should happen?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, we have tests in gaf that are specifically focussing in this logic (openbox). The test goal here is error behaviour on a closed box level.

@PeterSchafer PeterSchafer force-pushed the chore/CLI-1494_fault_injection branch from 07a89e6 to a61fdab Compare May 18, 2026 17:01
@snyk-pr-review-bot

This comment has been minimized.

@snyk-pr-review-bot

This comment has been minimized.

@robertolopezlopez robertolopezlopez force-pushed the chore/CLI-1494_fault_injection branch from 6e8030d to 084be22 Compare May 19, 2026 07:44
@snyk-pr-review-bot

This comment has been minimized.

@robertolopezlopez robertolopezlopez changed the title chore: add resilience-test suite and remove individual test chore: unify resilience tests and add 401/mid-execution-maintenance scenarios May 19, 2026
@PeterSchafer PeterSchafer force-pushed the chore/CLI-1494_fault_injection branch from 084be22 to 8e496d9 Compare May 19, 2026 08:29
@PeterSchafer PeterSchafer enabled auto-merge May 19, 2026 08:32
@snyk-pr-review-bot

Copy link
Copy Markdown

PR Reviewer Guide 🔍

🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Test Logic Error 🟠 [major]

The 'mid-execution-maintenance' scenario (Scenario 4) is configured to return success (200) for the first 4 requests and then switch to maintenance mode (503). While the code correctly skips 'whoami' and 'auth' as single-request commands, it fails to skip other short-lived commands like test, monitor, and sbom. In a test environment (scanning the repo root), these commands typically complete in fewer than 5 requests. Consequently, they will receive success for all calls and exit with code 0, which will cause the test assertion to fail as it expects EXIT_CODES.EX_TEMPFAIL (11).

  server.setNextStatusCode(200);
  server.setNextStatusCode(200);
  server.setNextStatusCode(200);
  server.setNextStatusCode(200);
  server.setGlobalResponse(
    maintenanceErrorRes,
    parseInt(maintenanceErrorRes.errors[0].status),
  );
},
expectedExitCode: EXIT_CODES.EX_TEMPFAIL,
expectedErrorCode: 'SNYK-0099',
skip: [
  'whoami', // Single-request commands won't hit the failure
  'auth', // Single-request commands won't hit the failure
  'container monitor scratch',
],
Coverage Gap 🟡 [minor]

In Scenario 3 ('unauthorized-401'), the auth command is explicitly skipped. This is a significant coverage gap because the auth command's primary purpose is credential verification. Ensuring that it handles 401 responses gracefully and consistently with other commands is critical for the stated goal of 'Consistent CLI Behavior'.

'auth', // auth doesn't need to
📚 Repository Context Analyzed

This review considered 5 relevant code sections from 4 files (average relevance: 1.00)

@PeterSchafer PeterSchafer merged commit b5ae18c into main May 19, 2026
9 checks passed
@PeterSchafer PeterSchafer deleted the chore/CLI-1494_fault_injection branch May 19, 2026 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants